package com.neusoft.elm_servlet.controller;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neusoft.elm_servlet.po.User;
import com.neusoft.elm_servlet.service.UserService;
import com.neusoft.elm_servlet.service.impl.UserServiceImpl;

public class UserController {
	
	UserService userService = new UserServiceImpl();
	
	public User getUserByIdByPass(HttpServletRequest request,HttpServletResponse response){
		String userId = request.getParameter("userId");
		String password = request.getParameter("password");
		User user = null;
		try {
			user = userService.getUserByIdByPass(userId,password);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return user;
	}
	
	public int getUserById(HttpServletRequest request,HttpServletResponse response){
		String userId = request.getParameter("userId");
		int count = 0;
		try {
			count = userService.getUserById(userId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return count;
	}
	
	
	public int saveUser(HttpServletRequest request,HttpServletResponse response){
		String userId = request.getParameter("userId");
		String password = request.getParameter("password");
		String userName = request.getParameter("userName");
		String userSex = request.getParameter("userSex");
		User user = new User();
		user.setUserId(userId);
		user.setPassword(password);
		user.setUserName(userName);
		user.setUserSex(Integer.valueOf(userSex));
		int count = 0;
		try {
			count = userService.saveUser(user);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return count;
	}

}
